package com.ljt.kotlinandmvvm.main.activity

import android.view.View
import com.ljt.base.activity.BaseActivity
import com.ljt.base.utils.GlideUtils
import com.ljt.kotlinandmvvm.R
import com.ljt.kotlinandmvvm.databinding.ActivityMainBinding
import com.ljt.kotlinandmvvm.main.adapter.MainViewPagerAdapter

public class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(),
    View.OnClickListener {

    lateinit var vpAdapter: MainViewPagerAdapter


    override fun getLayoutResId(): Int {
        return R.layout.activity_main
    }

    override fun createViewModel(): MainViewModel {
        return MainViewModel()
    }

    override fun initView() {
        binding.activity = this
        binding.llModuleFirstPage.setOnClickListener(this)
        binding.llModuleFoodDesc.setOnClickListener(this)
        binding.llModuleShoppingCart.setOnClickListener(this)
        binding.llModuleMy.setOnClickListener(this)
    }

    override fun initData() {
        vpAdapter = MainViewPagerAdapter(supportFragmentManager)
        binding.vpModule.adapter = vpAdapter
        binding.vpModule.currentItem = 0
    }

    override fun onClick(v: View?) {
        var id = v!!.id
        if (id == R.id.llModuleFirstPage){
            initBottomIV()
            GlideUtils.glideResToImage(this,R.drawable.index1,binding.ivModuleFirstPage)
            binding.tvModulePageFirst.setTextColor(resources.getColor(R.color.orange,theme))
            binding.vpModule.setCurrentItem(0,false)
        }else if (id == R.id.llModuleFoodDesc){
            initBottomIV()
            GlideUtils.glideResToImage(this,R.drawable.icon1,binding.ivModuleFoodDesc)
            binding.tvModuleFoodDesc.setTextColor(resources.getColor(R.color.orange,theme))
            binding.vpModule.setCurrentItem(1,false)
        }else if (id == R.id.llModuleShoppingCart){
            initBottomIV()
            GlideUtils.glideResToImage(this,R.drawable.cart1,binding.ivModuleShoppingCart)
            binding.tvModuleShoppingCart.setTextColor(resources.getColor(R.color.orange,theme))
            binding.vpModule.setCurrentItem(2,false)
        }else if (id == R.id.llModuleMy){
            initBottomIV()
            GlideUtils.glideResToImage(this,R.drawable.mine1,binding.ivModuleMy)
            binding.tvModuleMy.setTextColor(resources.getColor(R.color.orange,theme))
            binding.vpModule.setCurrentItem(3,false)
        }
    }

    /**
     * 初始化主界面底部图片、文字颜色
     */
    fun initBottomIV(){
        GlideUtils.glideResToImage(this,R.drawable.index,binding.ivModuleFirstPage)
        GlideUtils.glideResToImage(this,R.drawable.icon,binding.ivModuleFoodDesc)
        GlideUtils.glideResToImage(this,R.drawable.cart,binding.ivModuleShoppingCart)
        GlideUtils.glideResToImage(this,R.drawable.mine,binding.ivModuleMy)

        initBottumTv()
    }

    /**
     * 初始化底部导航栏文字颜色
     */
    fun initBottumTv(){
        binding.tvModulePageFirst.setTextColor(resources.getColor(R.color.black,theme))
        binding.tvModuleFoodDesc.setTextColor(resources.getColor(R.color.black,theme))
        binding.tvModuleShoppingCart.setTextColor(resources.getColor(R.color.black,theme))
        binding.tvModuleMy.setTextColor(resources.getColor(R.color.black,theme))
    }

}

